home *** CD-ROM | disk | FTP | other *** search
/ SCI Games E3 2005 Press Kit (USA) / SCI Games E3 2005 Press Kit (USA).bin / runme_mac.swf / scripts / __Packages / mx / controls / Loader.as next >
Text File  |  2005-05-05  |  7KB  |  278 lines

  1. class mx.controls.Loader extends mx.core.View
  2. {
  3.    static var symbolName = "Loader";
  4.    static var symbolOwner = mx.controls.Loader;
  5.    static var version = "2.0.1.78";
  6.    var className = "Loader";
  7.    var clipParameters = {autoLoad:1,scaleContent:1,contentPath:1};
  8.    static var mergedClipParameters = mx.core.UIObject.mergeClipParameters(mx.controls.Loader.prototype.clipParameters,mx.core.View.prototype.clipParameters);
  9.    var __autoLoad = true;
  10.    var __bytesLoaded = undefined;
  11.    var __bytesTotal = undefined;
  12.    var __contentPath = undefined;
  13.    var __scaleContent = true;
  14.    function Loader()
  15.    {
  16.       super();
  17.    }
  18.    function init()
  19.    {
  20.       super.init();
  21.    }
  22.    function setSize(w, h, noEvent)
  23.    {
  24.       this._origWidth = w;
  25.       this._origHeight = h;
  26.       super.setSize(w,h,noEvent);
  27.       if(_global.isLivePreview)
  28.       {
  29.          this.livePreview._width = this.__width - 1;
  30.          this.livePreview._height = this.__height - 1;
  31.       }
  32.    }
  33.    function draw()
  34.    {
  35.       this.size();
  36.    }
  37.    function size()
  38.    {
  39.       super.size();
  40.       if(this.__scaleContent)
  41.       {
  42.          this.doScaleContent();
  43.       }
  44.       else
  45.       {
  46.          this.doScaleLoader();
  47.       }
  48.    }
  49.    function createChildren()
  50.    {
  51.       super.createChildren();
  52.       if(_global.isLivePreview)
  53.       {
  54.          this.createTextField("livePreview",-1000,0,0,99,99);
  55.          this.livePreview.text = "mx.controls.Loader";
  56.          this.livePreview.border = true;
  57.       }
  58.       if(this.__autoLoad)
  59.       {
  60.          this.load();
  61.       }
  62.    }
  63.    function getAutoLoad()
  64.    {
  65.       return this.__autoLoad;
  66.    }
  67.    function get autoLoad()
  68.    {
  69.       return this.getAutoLoad();
  70.    }
  71.    function setAutoLoad(b)
  72.    {
  73.       if(this.__autoLoad != b)
  74.       {
  75.          this.__autoLoad = b;
  76.          if(this.__autoLoad && !this[mx.core.View.childNameBase + 0]._complete)
  77.          {
  78.             this.load();
  79.          }
  80.       }
  81.    }
  82.    function set autoLoad(b)
  83.    {
  84.       this.setAutoLoad(b);
  85.    }
  86.    function getBytesLoaded()
  87.    {
  88.       return this.__bytesLoaded;
  89.    }
  90.    function get bytesLoaded()
  91.    {
  92.       return this.getBytesLoaded();
  93.    }
  94.    function getBytesTotal()
  95.    {
  96.       return this.__bytesTotal;
  97.    }
  98.    function get bytesTotal()
  99.    {
  100.       return this.getBytesTotal();
  101.    }
  102.    function getContent()
  103.    {
  104.       return this.contentHolder;
  105.    }
  106.    function get content()
  107.    {
  108.       return this.getContent();
  109.    }
  110.    function getContentPath()
  111.    {
  112.       return this.__contentPath;
  113.    }
  114.    function get contentPath()
  115.    {
  116.       return this.getContentPath();
  117.    }
  118.    function setContentPath(url)
  119.    {
  120.       if(this.__contentPath != url)
  121.       {
  122.          this.__contentPath = url;
  123.          if(this.childrenCreated)
  124.          {
  125.             if(this.__autoLoad)
  126.             {
  127.                this.load();
  128.             }
  129.          }
  130.       }
  131.    }
  132.    function set contentPath(c)
  133.    {
  134.       this.setContentPath(c);
  135.    }
  136.    function getPercentLoaded()
  137.    {
  138.       var _loc2_ = 100 * (this.__bytesLoaded / this.__bytesTotal);
  139.       if(isNaN(_loc2_))
  140.       {
  141.          _loc2_ = 0;
  142.       }
  143.       return _loc2_;
  144.    }
  145.    function get percentLoaded()
  146.    {
  147.       return this.getPercentLoaded();
  148.    }
  149.    function get scaleContent()
  150.    {
  151.       return this.getScaleContent();
  152.    }
  153.    function getScaleContent()
  154.    {
  155.       return this.__scaleContent;
  156.    }
  157.    function setScaleContent(b)
  158.    {
  159.       if(this.__scaleContent != b)
  160.       {
  161.          this.__scaleContent = b;
  162.          if(this.__scaleContent)
  163.          {
  164.             this.doScaleContent();
  165.          }
  166.          else
  167.          {
  168.             this.doScaleLoader();
  169.          }
  170.       }
  171.    }
  172.    function set scaleContent(b)
  173.    {
  174.       this.setScaleContent(b);
  175.    }
  176.    function load(url)
  177.    {
  178.       if(url != undefined)
  179.       {
  180.          this.__contentPath = url;
  181.       }
  182.       if(this[mx.core.View.childNameBase + 0] != undefined)
  183.       {
  184.          if(this[mx.core.View.childNameBase + 0]._complete)
  185.          {
  186.             this.setSize(this._origWidth,this._origHeight);
  187.          }
  188.          this.destroyChildAt(0);
  189.       }
  190.       if(this.__contentPath == undefined || this.__contentPath == "")
  191.       {
  192.          return undefined;
  193.       }
  194.       this.createChild(this.__contentPath,"contentHolder");
  195.    }
  196.    function childLoaded(obj)
  197.    {
  198.       super.childLoaded(obj);
  199.       obj._rotation = 0;
  200.       this._origWidth = this.__width;
  201.       this._origHeight = this.__height;
  202.       if(this.__scaleContent)
  203.       {
  204.          this.doScaleContent();
  205.       }
  206.       else
  207.       {
  208.          this.doScaleLoader();
  209.       }
  210.    }
  211.    function dispatchEvent(obj)
  212.    {
  213.       if(obj.type == "progress" || obj.type == "complete")
  214.       {
  215.          obj.target = this;
  216.          this.__bytesTotal = obj.total;
  217.          this.__bytesLoaded = obj.current;
  218.       }
  219.       super.dispatchEvent(obj);
  220.    }
  221.    function doScaleContent()
  222.    {
  223.       if(!this[mx.core.View.childNameBase + 0]._complete)
  224.       {
  225.          return undefined;
  226.       }
  227.       this.unScaleContent();
  228.       var _loc2_ = this.border_mc.__get__borderMetrics();
  229.       var _loc7_ = this._origWidth - _loc2_.left - _loc2_.right;
  230.       var _loc6_ = this._origHeight - _loc2_.top - _loc2_.bottom;
  231.       var _loc9_ = _loc2_.left;
  232.       var _loc8_ = _loc2_.top;
  233.       var _loc5_ = _loc7_ / this.contentHolder._width;
  234.       var _loc3_ = _loc6_ / this.contentHolder._height;
  235.       var _loc4_ = undefined;
  236.       if(_loc5_ > _loc3_)
  237.       {
  238.          _loc9_ = _loc2_.left + Math.floor((_loc7_ - this.contentHolder._width * _loc3_) / 2);
  239.          _loc4_ = _loc3_;
  240.       }
  241.       else
  242.       {
  243.          _loc8_ = _loc2_.top + Math.floor((_loc6_ - this.contentHolder._height * _loc5_) / 2);
  244.          _loc4_ = _loc5_;
  245.       }
  246.       _loc4_ *= 100;
  247.       this.contentHolder._xscale = this.contentHolder._yscale = _loc4_;
  248.       this.contentHolder._x = _loc9_;
  249.       this.contentHolder._y = _loc8_;
  250.       if(this.__width != this._origWidth || this.__height != this._origHeight)
  251.       {
  252.          this.setSize(this._origWidth,this._origHeight);
  253.       }
  254.    }
  255.    function doScaleLoader()
  256.    {
  257.       if(!this[mx.core.View.childNameBase + 0]._complete)
  258.       {
  259.          return undefined;
  260.       }
  261.       this.unScaleContent();
  262.       var _loc2_ = this.border_mc.__get__borderMetrics();
  263.       var _loc4_ = this.contentHolder._width + _loc2_.left + _loc2_.right;
  264.       var _loc3_ = this.contentHolder._height + _loc2_.top + _loc2_.bottom;
  265.       if(this.__width != _loc4_ || this.__height != _loc3_)
  266.       {
  267.          this.setSize(_loc4_,_loc3_);
  268.       }
  269.       this.contentHolder._x = _loc2_.left;
  270.       this.contentHolder._y = _loc2_.top;
  271.    }
  272.    function unScaleContent()
  273.    {
  274.       this.contentHolder._xscale = this.contentHolder._yscale = 100;
  275.       this.contentHolder._x = this.contentHolder._y = 0;
  276.    }
  277. }
  278.